package com.rabbitmq.demo.controller;

import com.rabbitmq.demo.conf.TopicQueueConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 主题模式生产者
 *
 * @Author yi.cheng
 * @Date 2023-7-13 13:24
 **/
@RestController
public class TopicQueueProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/api/topic")
    public String sendTopicQueueMsg(@RequestParam String message, @RequestParam String routingKey){
        rabbitTemplate.convertAndSend(TopicQueueConfig.TOPIC_EXCHANGE_NAME, routingKey,message.getBytes());
        return "ok";
    }
}
